package co.edu.uniandes.moviles.rollerjudge;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.provider.CalendarContract;
import android.provider.CalendarContract.Events;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.Spinner;
import co.edu.uniandes.moviles.rollerjudge.logica.Deportista;
import co.edu.uniandes.moviles.rollerjudge.logica.Equipo;
import co.edu.uniandes.moviles.rollerjudge.logica.RollerJudge;

public class EstadisticasActivity extends Activity{

	protected static final int DATE_DIALOG_ID = 999;
	private String nombre;
	private String email;
	private String asunto;
	private Spinner spinner1;



	@Override
	protected void onCreate(Bundle savedInstanceState) {
		RollerJudge roller = RollerJudge.darInstancia();
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_estadistica);



		spinner1 = (Spinner) findViewById(R.id.spinner1);
		List<String> list = new ArrayList<String>();
		for(int i=0;i<roller.darEquipos().size();i++)
		{
			Equipo eq= roller.darEquipos().get(i);
			list.add("Grupo-"+eq.getNombre());

		}
		for(int i=0;i<roller.darPatinadores().size();i++)
		{
			Deportista eq= roller.darPatinadores().get(i);
			list.add("Patinador-"+eq.getNombre());

		}

		ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,
				android.R.layout.simple_spinner_item, list);
		dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		spinner1.setAdapter(dataAdapter);


	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}



	@SuppressWarnings("deprecation")
	public void showDialog(String title, String message, final boolean finishAfterClose) {
		AlertDialog alertDialog = new AlertDialog.Builder(this).create();
		alertDialog.setTitle(title);
		alertDialog.setMessage(message);
		alertDialog.setButton("Aceptar", new DialogInterface.OnClickListener() {
			@Override
			public void onClick(final DialogInterface dialog, final int which) {				
				if(finishAfterClose){
					finish();
				}
			}
		});
		alertDialog.show();
	}

	public void consultar(View view){
		

		spinner1 = (Spinner) findViewById(R.id.spinner1);	

		nombre = String.valueOf(spinner1.getSelectedItem());
	
		RollerJudge roller = RollerJudge.darInstancia();
		String[] split = nombre.split("-");
		if(split[0].equals("Grupo"))
		{
			showDialog("Estadisticas", roller.estadiGrupo(split[1]), true);
		}
		else
		{
			showDialog("Estadisticas", roller.estadiGrupo(split[1]), true);
		}
		System.out.println("nombre:" + nombre  );
		
	
		
		


	}

}


